﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;

namespace HZ.DrugTrade.Web.Enterprise.SystemManage
{
    public partial class CompanySCList : System.Web.UI.Page
    {
        IBLL_Company ic = Factory.BLL_Company();

        IBLL_SelectRelation iselectRelation = Factory.BLL_SelectRelation();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCompanyInfo();

            }
        }
        private void BindCompanyInfo()
        {
            //从页面获取分页大小
            int totalCount;
            AspNetPager1.PageSize = 10;
            string strWhere = "";


            if (string.IsNullOrEmpty(txtCompanyName.Text.Trim()) == false && !string.IsNullOrEmpty(HZ.Fun2.CheckString(txtCompanyName.Text.Trim())))
            {
                strWhere += " and TB_CompanyInfo.companyname like '%" + txtCompanyName.Text.Trim() + "%' ";
            }
            strWhere += " and TB_CompanyInfo.companyid not in (select userid from tb_user where isusing = 0) and TB_CompanyInfo.Companyid like 'QS%' or TB_CompanyInfo.companyid like 'QJ%'"; 
            strWhere += "  order by TB_CompanyInfo.companyname";
            DataTable dt = ic.GetCompanySCInfoByWhere(strWhere, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwCheckList.DataSource = dt;
            gvwCheckList.DataBind();

            this.gvwCheckList.Height = this.gvwCheckList.Rows.Count * 30 + 50;
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindCompanyInfo();

        }
        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            BindCompanyInfo();
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount;
            string strWhere = "";


            if (string.IsNullOrEmpty(txtCompanyName.Text.Trim()) == false && !string.IsNullOrEmpty(HZ.Fun2.CheckString(txtCompanyName.Text.Trim())))
            {
                strWhere += " and TB_CompanyInfo.companyname like '%" + txtCompanyName.Text.Trim() + "%' ";
            }
            strWhere += "  order by TB_CompanyInfo.companyname";
            DataTable dt = ic.GetCompanySCInfoByWhere(strWhere,1, 0, out totalCount);
            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvwCheckList);
        }
    }
}
